package cn.janyd.jmall.management.controller.admin;

import cn.janyd.common.core.vo.CommonResult;
import cn.janyd.jmall.management.controller.admin.dto.AdminCreateDTO;
import cn.janyd.jmall.management.controller.admin.vo.AdminVO;
import cn.janyd.jmall.management.manager.admin.AdminManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import static cn.janyd.common.core.vo.CommonResult.success;

/**
 * @author Janyd
 * @since 2020-08-15 17:24
 */
@Api(tags = "管理员 API")
@RestController
@RequestMapping("/admin")
@AllArgsConstructor
public class AdminController {

    private final AdminManager adminManager;

    private final ApplicationContext applicationContext;

    @ApiOperation("获取管理员信息")
    @GetMapping("/{adminId}")
    public CommonResult<AdminVO> getAdmin(@PathVariable("adminId") Integer adminId) {
        AdminVO admin = adminManager.getAdmin(adminId);
        return success(admin);
    }

    @ApiOperation("创建管理员")
    @PostMapping("/create")
    public CommonResult<AdminVO> createAdmin(@RequestBody @Valid AdminCreateDTO adminCreate) {
        AdminVO admin = adminManager.createAdmin(adminCreate);
        return success(admin);
    }
}
